home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / Source / Chapter 10 / Test / Main.cpp next >
Encoding:
C/C++ Source or Header  |  2004-08-05  |  3.5 KB  |  89 lines

  1. //-----------------------------------------------------------------------------
  2. // System Includes
  3. //-----------------------------------------------------------------------------
  4. #include <windows.h>
  5.  
  6. //-----------------------------------------------------------------------------
  7. // Engine Includes
  8. //-----------------------------------------------------------------------------
  9. #include "..\Engine\Engine.h"
  10.  
  11. //-----------------------------------------------------------------------------
  12. // Test State Class
  13. //-----------------------------------------------------------------------------
  14. class TestState : public State
  15. {
  16. public:
  17.     //-------------------------------------------------------------------------
  18.     // Allows the test state to preform any pre-processing construction.
  19.     //-------------------------------------------------------------------------
  20.     virtual void Load()
  21.     {
  22.         // Load the text scene.
  23.         g_engine->GetSceneManager()->LoadScene( "Abandoned City.txt", "./Assets/" );
  24.  
  25.         // Create a scene object that will be used as a camera.
  26.         g_engine->GetSceneManager()->AddObject( m_viewer = new SceneObject );
  27.         m_viewer->SetTranslation( 0.0f, 200.0f, -500.0f );
  28.         m_viewer->SetFriction( 5.0f );
  29.     };
  30.  
  31.     //-------------------------------------------------------------------------
  32.     // Returns the view setup details for the given frame.
  33.     //-------------------------------------------------------------------------
  34.     virtual void RequestViewer( ViewerSetup *viewer )
  35.     {
  36.         viewer->viewer = m_viewer;
  37.         viewer->viewClearFlags = D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER;
  38.     }
  39.  
  40.     //-------------------------------------------------------------------------
  41.     // Updates the test state.
  42.     //-------------------------------------------------------------------------
  43.     virtual void Update( float elapsed )
  44.     {
  45.         // Allow the camera (scene object) to be moved around.
  46.         if( g_engine->GetInput()->GetKeyPress( DIK_W, true ) == true )
  47.             m_viewer->Drive( 4000.0f * elapsed, false );
  48.         if( g_engine->GetInput()->GetKeyPress( DIK_S, true ) == true )
  49.             m_viewer->Drive( -4000.0f * elapsed, false );
  50.         if( g_engine->GetInput()->GetKeyPress( DIK_A, true ) == true )
  51.             m_viewer->Strafe( -4000.0f * elapsed, false );
  52.         if( g_engine->GetInput()->GetKeyPress( DIK_D, true ) == true )
  53.             m_viewer->Strafe( 4000.0f * elapsed, false );
  54.  
  55.         // Adjust the rotation of the camera based on the mouse movement.
  56.         m_viewer->AddRotation( (float)g_engine->GetInput()->GetDeltaY() * elapsed, (float)g_engine->GetInput()->GetDeltaX() * elapsed, 0.0f );
  57.     };
  58.  
  59. private:
  60.     SceneObject *m_viewer; // The viewer scene object is used as a camera.
  61. };
  62.  
  63. //-----------------------------------------------------------------------------
  64. // Application specific state setup.
  65. //-----------------------------------------------------------------------------
  66. void StateSetup()
  67. {
  68.     g_engine->AddState( new TestState, true );
  69. }
  70.  
  71. //-----------------------------------------------------------------------------
  72. // Entry point for the application.
  73. //-----------------------------------------------------------------------------
  74. int WINAPI WinMain( HINSTANCE instance, HINSTANCE prev, LPSTR cmdLine, int cmdShow )
  75. {
  76.     // Create the engine setup structure.
  77.     EngineSetup setup;
  78.     setup.instance = instance;
  79.     setup.name = "Scene Test";
  80.     setup.scale = 0.01f;
  81.     setup.StateSetup = StateSetup;
  82.     setup.spawnerPath = "./Assets/Spawners/";
  83.  
  84.     // Create the engine (using the setup structure), then run it.
  85.     new Engine( &setup );
  86.     g_engine->Run();
  87.  
  88.     return true;
  89. }